package com.zl.common;

import com.zl.enums.Status;
import lombok.Data;

/**
 * 统一返回
 *
 * @param
 */
@Data
public class Result {


    private boolean success;
    /**
     * 编码
     */
    private int code;
    /**
     * 内容
     */
    private String msg;

    /**
     * 返回类
     */
    private Object data;

    public Result() {
    }

    public Result(boolean success, int code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public Result(boolean success, int code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 默认的成功
     *
     * @return
     */
    public static Result success() {
        return new Result(true, Status.SUCCESS.Code, Status.SUCCESS.msg);
    }

    /**
     * 默认的成功
     *
     * @return
     */
    public static Result success(Object data) {
        return new Result(true, Status.SUCCESS.Code, Status.SUCCESS.msg, data);
    }

    /**
     * 默认的失败
     *
     * @return
     */
    public static Result error() {
        return new Result(false, Status.FAIL.Code, Status.FAIL.msg);
    }

    public static Result error(String msg) {
        return new Result(false, Status.FAIL.Code, msg);
    }

    public static Result error(int code, String msg) {
        return new Result(false, code, msg);
    }

}
